#include "Lake.h"

Lake::Lake(WorldEnums::eSceneryObjects sceneryId, Ogre::String mName, int mCapacity, NxOgre::SceneGeometry *mActor, Ogre::SceneNode* mSceneNode, Ogre::Entity* mEntity) : ActorEntitySceneNode(sceneryId, ActorEntitySceneNode::Emitter_Holder, mName, mActor, mSceneNode, mEntity)
{
	this->mCapacity = mCapacity;
	this->mCurrentLevel = 0;
}

//----------------------------------------------------------------------------------------------------------------

Lake::~Lake(void)
{
	int count = attachedEmitters.size();

	for(int i=0;i<count;i++)
	{
		delete attachedEmitters.at(i);
	}
	attachedEmitters.clear();
}

//----------------------------------------------------------------------------------------------------------------

int Lake::getNumEmitters(void)
{
	return attachedEmitters.size();
}

//----------------------------------------------------------------------------------------------------------------

void Lake::setCapacity(int capacity)
{
	mCapacity = capacity;
}

//----------------------------------------------------------------------------------------------------------------

int Lake::getCapacity(void)
{
	return mCapacity;
}

//----------------------------------------------------------------------------------------------------------------

void Lake::setCurrentLevel(int level)
{
	mCurrentLevel = level;
}

//----------------------------------------------------------------------------------------------------------------

int Lake::getCurrentLevel(void)
{
	return mCurrentLevel;
}

//----------------------------------------------------------------------------------------------------------------

void Lake::incLevel(int value)
{
	mCurrentLevel+=value;
	if(mCurrentLevel>mCapacity)
	{
		fireAllEmitters(mCurrentLevel-mCapacity);
		mCurrentLevel = mCapacity;
	}
}

//----------------------------------------------------------------------------------------------------------------

void Lake::fireEmitter(int index, int particleSize)
{
	if((index>=0)&&(index<attachedEmitters.size()))
	{
		attachedEmitters.at(index)->makeWaterEmitter();
	}
}

//----------------------------------------------------------------------------------------------------------------

void Lake::fireAllEmitters(int particleSize)
{
	int count = attachedEmitters.size();

	int distributedParticleSize = particleSize / count;

	for(int i=0;i<count;i++)
	{
		fireEmitter(i, distributedParticleSize);
	}
}

//----------------------------------------------------------------------------------------------------------------

WaterEmitter *Lake::getEmitter(int index)
{
	if((index>=0)&&(index<attachedEmitters.size()))
	{
		return attachedEmitters.at(index);
	}
	else
	{
		return 0;
	}
}

//----------------------------------------------------------------------------------------------------------------

void Lake::attachEmitter(WaterEmitter *waterEmitter)
{
	attachedEmitters.push_back(waterEmitter);
}

//----------------------------------------------------------------------------------------------------------------